<!--{template header,admin}-->
<script src="js/admin.js" type="text/javascript"></script>
<script src="js/jquery.js" type="text/javascript"></script>
<script type="text/javascript">
function checkform(){
	var title=document.askform.title.value;
	if(''==title){
		alert('请填写调用名称!');
		return false;
	}
	return true;
}
</script>
<div style="width:100%; height:15px;color:#000;margin:0px 0px 10px;">
  <div style="float:left;"><a href="index.php?admin_main/stat{$setting['seo_suffix']}" target="main"><b>控制面板首页</b></a>&nbsp;&raquo;&nbsp;添加数据调用</div>
</div>
<!--{if isset($message)}-->
<!--{eval $type=isset($type)?$type:'correctmsg'; }-->
<table cellspacing="1" cellpadding="4" width="100%" align="center" class="tableborder">
	<tr>
		<td class="{$type}">{$message}</td>
	</tr>
</table>
<!--{/if}-->
		<form name="askform" action="index.php?admin_datacall/add{$setting['seo_suffix']}" method="post" onsubmit="return checkform();">
			<table cellspacing="1" cellpadding="4" width="100%" align="center" class="tableborder">
				<tr>
					<td class="altbg1" width="45%"><b>调用名称:</b><br><span class="smalltxt">数据调用名称</span></td>
					<td class="altbg2"><input name="title" type="text" id="title" /></td>
				</tr>
				<tr>
					<td class="altbg1" width="45%"><b>调用模板:</b><br>
						<span class="smalltxt">
							问题所在分类名: <a href="###"  onclick="insertunit('[category_name]');">[category_name]</a> 
							问题所在分类id: <a href="###"  onclick="insertunit('[category_name]');">[cid]</a><br>
							问题标题: <a href="###"  onclick="insertunit('[category_name]');">[title]</a> 
							问题id:  <a href="###"  onclick="insertunit('[category_name]');">[qid]</a><br>
							悬赏分:  <a href="###"  onclick="insertunit('[category_name]');">[price]</a><br>
							提问者: <a href="###"  onclick="insertunit('[category_name]');">[author]</a> 
							提问者uid: <a href="###"  onclick="insertunit('[category_name]');">[authorid]</a><br>
							提问时间: <a href="###"  onclick="insertunit('[category_name]');">[time]</a><br>
							回答数: <a href="###"  onclick="insertunit('[category_name]');">[answers]</a> 
							顶数: <a href="###"  onclick="insertunit('[category_name]');">[goods]</a><br>
							问题状态: <a href="###"  onclick="insertunit('[category_name]');">[status]</a>
						</span>
					</td>
					<td class="altbg2"><textarea  id="tpl_textarea" name="tpl"  style="height:100px;width:800px;"><a target="_blank" href="{SITE_URL}?question/view/[qid]{$setting['seo_suffix']}" >[title]</a> [<a target="_blank" href="{SITE_URL}?category/view/[cid]{$setting['seo_suffix']}">[category_name]</a>]<br /></textarea></td>
				</tr>
				<tr>
					<td class="altbg1" width="45%"><b>问题状态:</b><br><span class="smalltxt">选择要调用的问题状态</span></td>
					<td class="altbg2">
						<select name="status" >
						{loop $status_list $st}
						<option value="{$st[0]}">{$st[1]}</option>
						{/loop}
						</select>
					</td>
				</tr>
				<tr>
					<td class="altbg1" width="45%"><b>问题分类:</b><br><span class="smalltxt">请选择问题的分类</span></td>
					<td class="altbg2">
					<span id="classid">
						<table cellspacing="0" cellpadding="0" border="0">
							<tr>
								<td>
									<select id="ClassLevel1" style="WIDTH: 125px" size="8" name="classlevel1">
										<option selected></option>
									</select>
								</td>
								<td width="20">
									<div align="center"><b>→</b></div>
								</td>
								<td>
									<select id="ClassLevel2" style="WIDTH: 125px" size="8" name="classlevel2">
										<option selected></option>
									</select>
								</td>
								<td width="20">
									<div id="jiantou" align="center"><b>→</b></div>
								</td>
								<td>
									<select id="ClassLevel3" style="WIDTH: 125px" onchange="getCidValue();" size="8" name="classlevel3">
										<option selected></option>
									</select>
								</td>
							</tr>
							</table>
						</span>
					</td>
				</tr>
				<tr>
					<td class="altbg1" width="45%"><b>起始数据行数:</b><br><span class="smalltxt">设置数据起始行数，必须为整数</span></td>
					<td class="altbg2"><input name="start"  type="text" value="0" ></td>
				</tr>
				<tr>
					<td class="altbg1" width="45%"><b>显示数据条数:</b><br><span class="smalltxt">设置数据显示条数</span></td>
					<td class="altbg2"><input name="limit"  value="10"  type="text"></td>
				</tr>
				<tr>
					<td class="altbg1" width="45%"><b>标题最大字节数:</b><br><span class="smalltxt">设置标题字节数</span></td>
					<td class="altbg2"><input name="maxbyte"  type="text" value="38" ></td>
				</tr>
				<tr>
					<td class="altbg1" width="45%"><b>数据缓存时间(秒):</b><br><span class="smalltxt">设置数据缓存时间</span></td>
					<td class="altbg2"><input name="cachelife" value="1800" type="text"/></td>
				</tr>
				<tr>
					<td class="altbg1" width="45%"><b>显示数据条数:</b><br><span class="smalltxt">设置数据显示条数</span></td>
					<td class="altbg2"><input name="limit"  value="10"  type="text"></td>
				</tr>
			</table>
			<br />
			<input type="hidden" value="0" name="cid">
			<center><input type="submit" class="button" name="submit" value="提 交"></center><br>
		</form>
<br />
<!--{template footer,admin}-->
<script type="text/javascript">

	function isUndefined(variable) {
		return typeof variable == 'undefined' ? true : false;
	}

	function strlen(str) {
		return (document.all && str.indexOf('\n') != -1) ? str.replace(/\r?\n/g, '_').length : str.length;
	}
	
	function insertunit(text){
		$('#tpl_textarea').focus();
		textend =  '' ;
		moveend = 0 ;
		tplval=$('#tpl_textarea').val();
		startlen = strlen(tplval);
		endlen = strlen(textend);
		selstart=document.getElementById('tpl_textarea').selectionStart;
		selend=document.getElementById('tpl_textarea').selectionEnd;
		if(!isUndefined(selstart)) {
			var opn = selstart + 0;
			if(textend != '') {
				text = text + tplval.substring(selstart, selend) + textend;
			}
			tplval = tplval.substr(0, selstart) + text + tplval.substr(selend);
			if(!moveend) {
				selstart = opn + strlen(text) - endlen;
				selend = opn + strlen(text) - endlen;
			}

		} else if(document.selection && document.selection.createRange) {
			var sel = document.selection.createRange();
			if(textend != '') {
				text = text + sel.text + textend;
			}
			sel.text = text.replace(/\r?\n/g, '\r\n');
			if(moveend) {
				sel.moveStart('character', -endlen);
				sel.moveEnd('character', -endlen);
			}
			sel.select();
		} else {
			tplval += text;
		}
		$('#tpl_textarea').val(tplval);
	};
	var sortobj=eval('($category_js)');
	var g_ClassLevel1;
	var g_ClassLevel2;
	var g_ClassLevel3;
	var class_level_1=sortobj.category1;
	var class_level_2=sortobj.category2;
	var class_level_3=sortobj.category3;
	var button_noselect="不选择";

function getCidValue()
{
	var _cl1 = document.askform.ClassLevel1;
	var _cl2 = document.askform.ClassLevel2;
	var _cl3 = document.askform.ClassLevel3;
	var _cid = document.askform.cid;
	if(_cl1.value!=0) _cid.value = _cl1.value;
	if(_cl2.value!=0) _cid.value = _cl2.value;
	if(_cl3.value!=0) _cid.value = _cl3.value;
}
function FillClassLevel1(ClassLevel1)
{
    ClassLevel1.options[0] = new Option("aa", "0");
    for(i=0; i<class_level_1.length; i++)
    {
        ClassLevel1.options[i] = new Option(class_level_1[i][1], class_level_1[i][0]);
    }
    // ClassLevel1.options[0].selected = true;
    ClassLevel1.length = i;
}
function FillClassLevel2(ClassLevel2, class_level_1_id)
{
    ClassLevel2.options[0] = new Option(button_noselect, "");
    count = 1;
    for(i=0; i<class_level_2.length; i++){
    if(class_level_2[i][0].toString() == class_level_1_id) {
            ClassLevel2.options[count] = new Option(class_level_2[i][2], class_level_2[i][1]);
            count = count+1;}
    }
    ClassLevel2.options[0].selected = true;
    ClassLevel2.length = count;
}
function FillClassLevel3(ClassLevel3, class_level_2_id)
{
    ClassLevel3.options[0] = new Option(button_noselect, "");
    count = 1;
    for(i=0; i<class_level_3.length; i++) {
        if(class_level_3[i][0].toString() == class_level_2_id) {
            ClassLevel3.options[count] = new Option(class_level_3[i][2], class_level_3[i][1]);
            count = count+1;}
    }
    ClassLevel3.options[0].selected = true;
    ClassLevel3.length = count;       
}
function ClassLevel2_onchange()
{
    getCidValue();
    FillClassLevel3(g_ClassLevel3, g_ClassLevel2.value); 
    if (g_ClassLevel3.length <= 1) {  
     g_ClassLevel3.style.display = "none";
	 document.getElementById("jiantou").style.display = "none";
    }
    else {
     g_ClassLevel3.style.display = "";     
	 document.getElementById("jiantou").style.display = "";	 
    }       
}
 
function ClassLevel1_onchange()
{
    getCidValue();
    FillClassLevel2(g_ClassLevel2, g_ClassLevel1.value);
    ClassLevel2_onchange();
	
}
function InitClassLevelList(ClassLevel1, ClassLevel2, ClassLevel3)
{
    g_ClassLevel1=ClassLevel1;
    g_ClassLevel2=ClassLevel2;
    g_ClassLevel3=ClassLevel3;
    g_ClassLevel1.onchange = Function("ClassLevel1_onchange();");
    g_ClassLevel2.onchange = Function("ClassLevel2_onchange();");
    FillClassLevel1(g_ClassLevel1);
    ClassLevel1_onchange();
}
InitClassLevelList(document.askform.ClassLevel1, document.askform.ClassLevel2, document.askform.ClassLevel3);

var selected_id_list="0"
var blank_pos = selected_id_list.indexOf(" ");
var find_blank = true;
if (blank_pos == -1) {
    find_blank = false;
    blank_pos = selected_id_list.length;
}
var id_str = selected_id_list.substr(0, blank_pos);
g_ClassLevel1.value = id_str;
ClassLevel1_onchange();

if (find_blank == true) {
    selected_id_list = selected_id_list.substr(blank_pos + 1,   selected_id_list.length - blank_pos - 1);
    blank_pos = selected_id_list.indexOf(" ");
    if (blank_pos == -1) {
        find_blank = false;
        blank_pos = selected_id_list.length;
    }
    id_str = selected_id_list.substr(0, blank_pos);
    g_ClassLevel2.value = id_str;
    ClassLevel2_onchange();

    if (find_blank == true) {
        selected_id_list = selected_id_list.substr(blank_pos + 1,  selected_id_list.length - blank_pos - 1);
        blank_pos = selected_id_list.indexOf(" ");
        if (blank_pos == -1) {
            find_blank = false;
            blank_pos = selected_id_list.length;
        }
        id_str = selected_id_list.substr(0, blank_pos);
        g_ClassLevel3.value = id_str;
    }
}	
</script>